package org.lee.validate.controller;

import org.lee.validate.custom.group.Insert;
import org.lee.validate.custom.group.Update;
import org.lee.validate.vo.request.HelloRequest;
import org.lee.validate.vo.resp.Result;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * HelloController
 *
 * @author dralee
 * @date 2021-12-24 14:46:01
 **/
@RestController
public class HelloController {

    @GetMapping("/hello")
    public String hello() {
        return "Hello World!";
    }

    @GetMapping("/hello2")
    public Result hello2(@Validated HelloRequest request) {
        return Result.success(request.getName().concat("=").concat(String.valueOf(request.getAge())));
    }

    @GetMapping("/hello3")
    public String hello3(@Validated HelloRequest request) {
        return request.getName().concat("=").concat(String.valueOf(request.getAge()));
    }


    @PostMapping("/save")
    public Result save(@RequestBody @Validated(Insert.class) HelloRequest request) {
        return Result.success("saved:".concat(request.getName().concat("=").concat(String.valueOf(request.getAge()))));
    }

    @PostMapping("/update")
    public Result update(@RequestBody @Validated(Update.class) HelloRequest request) {
        return Result.success("updated:".concat(request.getName().concat("=").concat(String.valueOf(request.getAge()))));
    }
}
